local healthBar = require('components.health-bar')

local thisMaxHealth = 236
local thisHealth = thisMaxHealth
local matchFinished = false

local function init()
    healthBar.init()
end

local function update(dt)
    healthBar.update(dt)
end

local function drawBar()
    healthBar.setMaxHealth(thisMaxHealth)
    healthBar.setHealth(thisHealth)
    healthBar.drawBar()
end

local function add(newScore)
    thisHealth = thisHealth - newScore
    if thisHealth <= 0 then
        thisHealth = 0
        matchFinished = true
    end
    return matchFinished
end

local function setText(healthBarText)
    healthBar.setText(healthBarText)
end

local function reset()
    thisHealth = thisMaxHealth
    matchFinished = false
end

return{
    init = init,
    update = update,
    drawBar = drawBar,
    add = add,
    setText = setText,
    reset = reset
}